﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms.DataVisualization.Charting;

namespace EasyTrader.Signal
{
    using PricePointList = List<EasyTrader.Wave.PricePoint>;
    using PriceSignalList = List<PriceSignal>;
    using PriceWaveList = List<EasyTrader.Wave.PriceWave>;
    public class HogaSignalManager : EasyTrader.Signal.SignalManager
    {
        public HogaSignalManager()
            : base()
        {
        }
        private System.Windows.Forms.DataVisualization.Charting.Chart m_ChartCtrl = null;
        private ETDataSet m_EeasyTraderDataSet = null;
        public EasyTrader.ETDataSet EeasyTraderDataSet
        {
            get { return m_EeasyTraderDataSet; }
            set { m_EeasyTraderDataSet = value; }
        }
        private EasyTrader.Signal.ForecastingInfo m_ForecastInfo = new EasyTrader.Signal.ForecastingInfo();
        private EasyTrader.Signal.ForecastingInfo buyInfo = new EasyTrader.Signal.ForecastingInfo();
        private EasyTrader.Signal.ForecastingInfo sellInfo = new EasyTrader.Signal.ForecastingInfo();
        private EasyTrader.Signal.ForecastingInfo bidsInfo = new EasyTrader.Signal.ForecastingInfo();
        private EasyTrader.Signal.ForecastingInfo asksInfo = new EasyTrader.Signal.ForecastingInfo();

        private EasyTrader.Signal.HighLowInfo m_BuyHighLowInfo = new EasyTrader.Signal.HighLowInfo();
        private EasyTrader.Signal.HighLowInfo m_SellHighLowInfo = new EasyTrader.Signal.HighLowInfo();

        public void InitChartCtrl()
        {
            m_ChartCtrl = new System.Windows.Forms.DataVisualization.Charting.Chart();
            System.Windows.Forms.DataVisualization.Charting.ChartArea priceArea = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
            System.Windows.Forms.DataVisualization.Charting.Legend mainLegend = new System.Windows.Forms.DataVisualization.Charting.Legend();
            priceArea.Name = "Price";
            this.m_ChartCtrl.ChartAreas.Add(priceArea);
            mainLegend.BackColor = System.Drawing.Color.Transparent;
            mainLegend.DockedToChartArea = "Price";
            mainLegend.Name = "Legend1";
            System.Windows.Forms.DataVisualization.Charting.Series seriesBuy = new System.Windows.Forms.DataVisualization.Charting.Series();
            System.Windows.Forms.DataVisualization.Charting.Series seriesSell = new System.Windows.Forms.DataVisualization.Charting.Series();
            System.Windows.Forms.DataVisualization.Charting.Series seriesAveBuy = new System.Windows.Forms.DataVisualization.Charting.Series();
            System.Windows.Forms.DataVisualization.Charting.Series seriesAveSell = new System.Windows.Forms.DataVisualization.Charting.Series();

            //seriesRange.BorderColor = System.Drawing.Color.Black;
            seriesBuy.ChartArea = "Price";
            seriesBuy.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            //seriesRange.Color = System.Drawing.Color.LightGreen;
            seriesBuy.Legend = "Legend1";
            seriesBuy.Name = "Buy";

            seriesSell.ChartArea = "Price";
            seriesSell.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            //seriesPrice.Color = System.Drawing.Color.Blue;
            seriesSell.Legend = "Legend1";
            seriesSell.Name = "Sell";

            seriesAveBuy.ChartArea = "Price";
            seriesAveBuy.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            //seriesPrice.Color = System.Drawing.Color.Blue;
            seriesAveBuy.Legend = "Legend1";
            seriesAveBuy.Name = "AveBuy";

            seriesAveSell.ChartArea = "Price";
            seriesAveSell.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            //seriesPrice.Color = System.Drawing.Color.Blue;
            seriesAveSell.Legend = "Legend1";
            seriesAveSell.Name = "AveSell";

            this.m_ChartCtrl.Series.Add(seriesBuy);
            this.m_ChartCtrl.Series.Add(seriesSell);
            this.m_ChartCtrl.Series.Add(seriesAveBuy);
            this.m_ChartCtrl.Series.Add(seriesAveSell);
            this.m_ChartCtrl.Size = new System.Drawing.Size(1, 1);
        }

        public void SetChartData(EasyTrader.ETDataSet a_DataSet, int a_AveRange)
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (a_DataSet == null || GlobalVar.FutureMstDataDownloaded == false)
                return;

            m_ChartCtrl.Series["Sell"].Points.Clear();
            m_ChartCtrl.Series["Buy"].Points.Clear();
            m_ChartCtrl.Series["AveSell"].Points.Clear();
            m_ChartCtrl.Series["AveBuy"].Points.Clear();
            FutureMstTable dataTable = a_DataSet.GetFutureMstTable();
            int rowCount = dataTable.GetRowCount();
            double buyValue = 0;
            double sellValue = 0;
            for (int i = 0; i < rowCount; i++)
            {
                DataRow row = dataTable.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row["매수총호가건수"] == DBNull.Value)
                        continue;

                    buyValue = Convert.ToDouble(row["매수총호가건수"]);
                    sellValue = Convert.ToDouble(row["매도총호가건수"]);
                    m_ChartCtrl.Series["Buy"].Points.AddXY(i, buyValue);
                    m_ChartCtrl.Series["Sell"].Points.AddXY(i, sellValue);
                    m_ChartCtrl.Series["Buy"].Points[i].XValue = i;
                    int hour = Convert.ToInt32(row["시각"]);
                    if (hour != 0)
                        m_ChartCtrl.Series["Buy"].Points[i].AxisLabel = row["시각"].ToString();
                    else
                        m_ChartCtrl.Series["Buy"].Points[i].AxisLabel = GlobalVar.HogaDayIndexToTime(i).ToString();

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
            if (rowCount > a_AveRange + 1)
            {
                m_ChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, a_AveRange.ToString(), "Buy", "AveBuy");
                m_ChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, a_AveRange.ToString(), "Sell", "AveSell");
            }
        }

        public double GetBuyAveVal()
        {
            if (m_ChartCtrl == null)
                return -1.0;
            int pointCount = m_ChartCtrl.Series["AveBuy"].Points.Count;
            if (pointCount < GlobalVar.HogaValRefRange)
                return -1.0;

            double curBuyAveVal = m_ChartCtrl.Series["AveBuy"].Points[pointCount - 1].YValues[0];
            return curBuyAveVal;
        }

        public double GetBuyAveDayHigh(int a_AveRange, ref double a_lowSell)
        {
            if (m_ChartCtrl == null)
                return -1.0;
            int pointCount = m_ChartCtrl.Series["AveBuy"].Points.Count;
            if (pointCount < a_AveRange)
                return -1.0;

            double max = -9999999999;
            for (int i = 0; i < pointCount; i++)
            {
                double buyAve = m_ChartCtrl.Series["AveBuy"].Points[i].YValues[0];
                double sellAve = m_ChartCtrl.Series["AveSell"].Points[i].YValues[0];
                if (buyAve > max)
                {
                    max = buyAve;
                    a_lowSell = sellAve;
                }
            }

            return max;
        }

        public double GetSellAveDayHigh(int a_AveRange, ref double a_lowBuy)
        {
            if (m_ChartCtrl == null)
                return -1.0;
            int pointCount = m_ChartCtrl.Series["AveSell"].Points.Count;
            if (pointCount < a_AveRange)
                return -1.0;

            double max = -9999999999;
            for (int i = 0; i < pointCount; i++)
            {
                double buyAve = m_ChartCtrl.Series["AveBuy"].Points[i].YValues[0];
                double sellAve = m_ChartCtrl.Series["AveSell"].Points[i].YValues[0];
                if (sellAve > max)
                {
                    max = sellAve;
                    a_lowBuy = sellAve;
                }
            }

            return max;
        }

        public double GetBuyAveVal(int a_CurIndex)
        {
            if (m_ChartCtrl == null)
                return -1.0;
            int pointCount = m_ChartCtrl.Series["AveBuy"].Points.Count;
            if (pointCount < GlobalVar.HogaValRefRange)
                return -1.0;
            int curIndex = Math.Max(0, a_CurIndex);
            curIndex = Math.Min(curIndex, pointCount - 1);

            double curBuyAveVal = m_ChartCtrl.Series["AveBuy"].Points[curIndex].YValues[0];
            return curBuyAveVal;
        }

        public double GetSellAveVal()
        {
            if (m_ChartCtrl == null)
                return -1.0;
            int pointCount = m_ChartCtrl.Series["AveSell"].Points.Count;
            if (pointCount < GlobalVar.HogaValRefRange)
                return -1.0;

            double curSellAveVal = m_ChartCtrl.Series["AveSell"].Points[pointCount - 1].YValues[0];
            return curSellAveVal;
        }

        public double GetSellAveVal(int a_CurIndex)
        {
            if (m_ChartCtrl == null)
                return -1.0;
            int pointCount = m_ChartCtrl.Series["AveSell"].Points.Count;
            if (pointCount < GlobalVar.HogaValRefRange)
                return -1.0;
            int curIndex = Math.Max(0, a_CurIndex);
            curIndex = Math.Min(curIndex, pointCount - 1);

            double curSellAveVal = m_ChartCtrl.Series["AveSell"].Points[curIndex].YValues[0];
            return curSellAveVal;
        }

        public void SetChartData(int a_CurIndex, EasyTrader.ETDataSet a_DataSet, int a_AveRange)
        {
            // 데이터 셋 객체가 없으면 아무일도 하지 않는다.
            if (a_DataSet == null)
                return;

            m_ChartCtrl.Series["Sell"].Points.Clear();
            m_ChartCtrl.Series["Buy"].Points.Clear();
            m_ChartCtrl.Series["AveSell"].Points.Clear();
            m_ChartCtrl.Series["AveBuy"].Points.Clear();
            FutureMstTable dataTable = a_DataSet.GetFutureMstTable();
            int rowCount = dataTable.GetRowCount();
            if (rowCount == 0)
                return;
            if (rowCount - 1 < a_CurIndex)
                return;

            double buyValue = 0;
            double sellValue = 0;
            for (int i = 0; i <= a_CurIndex; i++)
            {
                DataRow row = dataTable.Rows[i];
                try
                {
                    // 값이 없을 경우는 넘어 간다.
                    if (row["매수총호가건수"] == DBNull.Value)
                        continue;

                    buyValue = Convert.ToDouble(row["매수총호가건수"]);
                    sellValue = Convert.ToDouble(row["매도총호가건수"]);
                    m_ChartCtrl.Series["Buy"].Points.AddXY(i, buyValue);
                    m_ChartCtrl.Series["Sell"].Points.AddXY(i, sellValue);
                    m_ChartCtrl.Series["Buy"].Points[i].XValue = i;
                    int hour = Convert.ToInt32(row["시각"]);
                    if (hour != 0)
                        m_ChartCtrl.Series["Buy"].Points[i].AxisLabel = row["시각"].ToString();
                    else
                        m_ChartCtrl.Series["Buy"].Points[i].AxisLabel = GlobalVar.HogaDayIndexToTime(i).ToString();

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }

            if (a_CurIndex + 1 > a_AveRange + 1)
            {
                m_ChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, a_AveRange.ToString(), "Buy", "AveBuy");
                m_ChartCtrl.DataManipulator.FinancialFormula(FinancialFormula.ExponentialMovingAverage, a_AveRange.ToString(), "Sell", "AveSell");
            }

        }
        private EasyTrader.Signal.ForecastingInfo m_buyVal = new EasyTrader.Signal.ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo BuyVal
        {
            get { return m_buyVal; }
            set { m_buyVal = value; }
        }
        private EasyTrader.Signal.ForecastingInfo m_sellVal = new EasyTrader.Signal.ForecastingInfo();
        public EasyTrader.Signal.ForecastingInfo SellVal
        {
            get { return m_sellVal; }
            set { m_sellVal = value; }
        }
        private EasyTrader.Wave.WaveManager m_BuyWaveManager = new EasyTrader.Wave.WaveManager();
        public EasyTrader.Wave.WaveManager BuyWaveManager
        {
            get { return m_BuyWaveManager; }
            set { m_BuyWaveManager = value; }
        }
        private EasyTrader.Wave.WaveManager m_SellWaveManager = new EasyTrader.Wave.WaveManager();
        public EasyTrader.Wave.WaveManager SellWaveManager
        {
            get { return m_SellWaveManager; }
            set { m_SellWaveManager = value; }
        }

        private int m_MaxBuyRealVal = 0;
        public int MaxBuyRealVal
        {
            get { return m_MaxBuyRealVal; }
            set { m_MaxBuyRealVal = value; }
        }
        private int m_MaxSellRealVal = 0;
        public int MaxSellRealVal
        {
            get { return m_MaxSellRealVal; }
            set { m_MaxSellRealVal = value; }
        }
        private int m_MaxBuyAverageVal = 0;
        public int MaxBuyAverageVal
        {
            get { return m_MaxBuyAverageVal; }
            set { m_MaxBuyAverageVal = value; }
        }
        private int m_MaxSellAverageVal = 0;
        public int MaxSellAverageVal
        {
            get { return m_MaxSellAverageVal; }
            set { m_MaxSellAverageVal = value; }
        }
        private int m_CurBuyRealVal = 0;
        public int CurBuyVal
        {
            get { return m_CurBuyRealVal; }
            set { m_CurBuyRealVal = value; }
        }
        private int m_CurSellRealVal = 0;
        public int CurSellVal
        {
            get { return m_CurSellRealVal; }
            set { m_CurSellRealVal = value; }
        }

        private int m_CurBuyAveVal = 0;
        public int CurBuyAveVal
        {
            get { return m_CurBuyAveVal; }
            set { m_CurBuyAveVal = value; }
        }
        private int m_CurSellAveVal = 0;
        public int CurSellAveVal
        {
            get { return m_CurSellAveVal; }
            set { m_CurSellAveVal = value; }
        }

        private PriceSignalList m_BuySignalList = new PriceSignalList();
        public PriceSignalList BuySignalList
        {
            get { return m_BuySignalList; }
            set { m_BuySignalList = value; }
        }
        private PriceSignalList m_SellSignalList = new PriceSignalList();
        public PriceSignalList SellSignalList
        {
            get { return m_SellSignalList; }
            set { m_SellSignalList = value; }
        }

        public int GetForecastingInfoByBeginEnd(ForecastingInfo a_Fore, string a_ColName, string a_RegType, int a_StartX, int a_EndX, bool a_AllowZero)
        {
            if (a_ColName == "" || a_Fore == null || a_StartX < 0 || a_EndX < 0)
                return -1;
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            int rowCount = curTable.GetRowCount();
            if (rowCount == 0)
                return -1;
            return Forecaster.GetForecastingInfoBeginEnd(a_Fore, curTable, a_ColName, a_RegType, a_StartX, a_EndX, a_AllowZero);
        }

        public EasyTrader.Wave.PriceWave FindSignalWave(int a_Index, int a_WaveType)
        {
            if (a_WaveType == GlobalVar.WaveTypeBuy)
            {
                return FindBuyWave(a_Index);
            }
            else if (a_WaveType == GlobalVar.WaveTypeSell)
            {
                return FindSellWave(a_Index);
            }

            return null;
        }
        public EasyTrader.Wave.PriceWave FindBuyWave(int a_Index)
        {
            PriceWaveList waveList = m_BuyWaveManager.ArragedWaveList;
            if (waveList.Count == 0)
                return null;

            for (int i = 0; i < waveList.Count; i++)
            {
                EasyTrader.Wave.PriceWave wave = waveList[i];
                if (wave.StartX <= a_Index && a_Index <= wave.EndX)
                    return wave;
            }

            return null;
        }

        public EasyTrader.Wave.PriceWave FindLastBuyWave(int a_Index)
        {
            PriceWaveList waveList = m_BuyWaveManager.ArragedWaveList;
            if (waveList.Count == 0)
                return null;

            return waveList[waveList.Count - 1];
        }

        public EasyTrader.Wave.PriceWave FindSellWave(int a_Index)
        {
            PriceWaveList waveList = m_SellWaveManager.ArragedWaveList;
            if (waveList.Count == 0)
                return null;

            for (int i = 0; i < waveList.Count; i++)
            {
                EasyTrader.Wave.PriceWave wave = waveList[i];
                if (wave.StartX <= a_Index && a_Index <= wave.EndX)
                    return wave;
            }

            return null;
        }

        public EasyTrader.Wave.PriceWave FindLastSellWave(int a_Index)
        {
            PriceWaveList waveList = m_SellWaveManager.ArragedWaveList;
            if (waveList.Count == 0)
                return null;

            return waveList[waveList.Count - 1];
        }

        public int FindHogaSignalBySummit(int a_CurIndex)
        {
            FindBuySellCurRealVal(a_CurIndex);
            FindBuySellMaxRealVal(a_CurIndex);
            MakeWave(a_CurIndex);
            FindBuySellCurAveVal(a_CurIndex);
            FindBuySellMaxAverageVal(a_CurIndex);
            int signalVal = GlobalVar.SignalNone;
            if (m_CurBuyRealVal == -1 ||
                m_CurSellRealVal == -1 ||
                m_MaxBuyRealVal == -1 ||
                m_MaxSellRealVal == -1 ||
                m_MaxBuyAverageVal == -1 ||
                m_MaxSellAverageVal == -1 ||
                m_CurBuyAveVal == -1 ||
                m_CurSellAveVal == -1)
                return signalVal;

            // 실제값과 평균값이 같은 위치에 있을 때만 신호를 낸다.
            if (m_CurBuyRealVal > m_CurSellRealVal)
            {
                if (m_CurBuyAveVal > m_CurSellAveVal)
                {
                    // 현재 평균 매수 건수가 정해진 최소건수보다 높을 때만 신호를 낸다.
                    if (m_CurBuyAveVal >= GlobalVar.MinHogaSignalLimit)
                    {
                        // 매수 호가 건수가 높을 경우이므로 이 경우는 매도 신호만 발생을 한다.
                        int realHighVal = m_MaxBuyRealVal - GlobalVar.MinHogaSignalRealVal;
                        int aveHighVal = m_MaxBuyAverageVal - GlobalVar.MinHogaSignalAverageVal;
                        // 평균값과 실제값이 동시에 조건을 만족할 때만 신호를 발생한다.
                        if (m_CurBuyRealVal <= realHighVal && m_CurBuyAveVal <= aveHighVal)
                        {
                            signalVal = GlobalVar.SignalSell;

                            EasyTrader.Signal.PriceSignal signal = null;
                            int signalCount = m_SellSignalList.Count;
                            if (signalCount == 0)
                            {
                                signal = new EasyTrader.Signal.PriceSignal();
                                signal.X = a_CurIndex;
                                signal.Y = m_CurBuyRealVal;
                                signal.Type = signalVal;
                                m_SellSignalList.Add(signal);
                                WriteSignalLog(a_CurIndex, signalVal, m_CurBuyRealVal, m_CurSellRealVal, "매수정점에서 매도신호발생함");
                            }
                            else
                            {
                                PriceSignal prevSignal = m_SellSignalList[signalCount - 1];
                                if (prevSignal.Type != signalVal)
                                {
                                    signal = new EasyTrader.Signal.PriceSignal();
                                    signal.X = a_CurIndex;
                                    signal.Y = m_CurBuyRealVal;
                                    signal.Type = signalVal;
                                    m_SellSignalList.Add(signal);
                                    WriteSignalLog(a_CurIndex, signalVal, m_CurBuyRealVal, m_CurSellRealVal, "매수정점에서 매도신호발생함");
                                }
                            }
                        }
                    }
                }
            }
            else if (m_CurBuyRealVal < m_CurSellRealVal)
            {
                if (m_CurBuyAveVal < m_CurSellAveVal)
                {
                    // 현재 평균 매도 건수가 정해진 최소건수보다 높을 때만 신호를 낸다.
                    if (m_CurSellAveVal >= GlobalVar.MinHogaSignalLimit)
                    {
                        // 매도 호가 건수가 높을 경우이므로 이 경우는 매수 신호만 발생을 한다.
                        int realHighVal = m_MaxSellRealVal - GlobalVar.MinHogaSignalRealVal;
                        int aveHighVal = m_MaxSellAverageVal - GlobalVar.MinHogaSignalAverageVal;
                        if (m_CurSellRealVal <= realHighVal && m_CurSellAveVal <= aveHighVal)
                        {
                            signalVal = GlobalVar.SignalBuy;

                            EasyTrader.Signal.PriceSignal signal = null;
                            int signalCount = m_BuySignalList.Count;
                            if (signalCount == 0)
                            {
                                signal = new EasyTrader.Signal.PriceSignal();
                                signal.X = a_CurIndex;
                                signal.Y = m_CurSellRealVal;
                                signal.Type = signalVal;
                                m_BuySignalList.Add(signal);
                                WriteSignalLog(a_CurIndex, signalVal, m_CurBuyRealVal, m_CurSellRealVal, "매도정점에서 매도신호발생함");
                            }
                            else
                            {
                                PriceSignal prevSignal = m_BuySignalList[signalCount - 1];
                                if (prevSignal.Type != signalVal)
                                {
                                    signal = new EasyTrader.Signal.PriceSignal();
                                    signal.X = a_CurIndex;
                                    signal.Y = m_CurSellRealVal;
                                    signal.Type = signalVal;
                                    m_BuySignalList.Add(signal);
                                    WriteSignalLog(a_CurIndex, signalVal, m_CurBuyRealVal, m_CurSellRealVal, "매도정점에서 매도신호발생함");
                                }
                            }
                        }
                    }
                }
            }

            return signalVal;
        }

        private void WriteSignalLog(int a_CurIndex, int a_Signal, int a_BuyVal, int a_SellVal, string a_HeaderMsg)
        {
            EasyTrader.Signal.PriceSignal lastSignal = GetLastSignal();
            if (lastSignal != null && lastSignal.Type == a_Signal)
                return;

            string logMsg = "파동에서 발생한 신호 :: " + a_HeaderMsg;
            logMsg += ", 인덱스 :" + a_CurIndex.ToString();
            logMsg += ", 현재시간 : " + GlobalVar.TimeToIntEx().ToString();
            logMsg += ", 현재 매수가격 : " + a_BuyVal.ToString();
            logMsg += ", 현재 매도가격 : " + a_SellVal.ToString();
            logMsg += ", 신호종류 : ";
            if (a_Signal == GlobalVar.SignalNone)
            {
                logMsg += "신호없음";
            }
            else if (a_Signal == GlobalVar.SignalSell)
            {
                logMsg += "매도";
            }
            else if (a_Signal == GlobalVar.SignalBuy)
            {
                logMsg += "매수";
            }
            else
            {
                logMsg += "알수없음";
            }

            GlobalVar.WriteLog(logMsg);
        }

        private void FindBuySellMaxRealVal(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;
            int rowCount = curTable.Rows.Count;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;

            m_MaxBuyRealVal = -1;
            m_MaxSellRealVal = -1;
            for (int i = 0; i < a_CurIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매수총호가건수"] == DBNull.Value)
                    return;
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                if (buy > m_MaxBuyRealVal)
                    m_MaxBuyRealVal = buy;
                if (sell > m_MaxSellRealVal)
                    m_MaxSellRealVal = sell;
            }
        }

        private void FindBuySellCurRealVal(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;
            int rowCount = curTable.Rows.Count;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;

            m_CurBuyRealVal = -1;
            m_CurSellRealVal = -1;
            
            DataRow row = curTable.Rows[a_CurIndex];
            if (row["매수총호가건수"] == DBNull.Value)
                return;
            m_CurBuyRealVal = Convert.ToInt32(row["매수총호가건수"]);
            m_CurSellRealVal = Convert.ToInt32(row["매도총호가건수"]);
        }

        private void FindBuySellMaxAverageVal(int a_CurIndex)
        {
            PricePointList pointList = m_BuyWaveManager.FilteredPointList;
            m_MaxBuyAverageVal = -1;
            for (int i = 0; i < pointList.Count; i++)
            {
                EasyTrader.Wave.PricePoint curPoint = pointList[i];
                int buy = Convert.ToInt32(curPoint.Y);
                if (buy > m_MaxBuyAverageVal)
                    m_MaxBuyAverageVal = buy;
            }

            pointList = m_SellWaveManager.FilteredPointList;
            m_MaxSellAverageVal = -1;
            for (int i = 0; i < pointList.Count; i++)
            {
                EasyTrader.Wave.PricePoint curPoint = pointList[i];
                int sell = Convert.ToInt32(curPoint.Y);
                if (sell > m_MaxSellAverageVal)
                    m_MaxSellAverageVal = sell;
            }
        }

        private void FindBuySellCurAveVal(int a_CurIndex)
        {
            PricePointList pointList = m_BuyWaveManager.FilteredPointList;
            m_CurBuyAveVal = -1;
            EasyTrader.Wave.PricePoint curPoint = null;
            if (pointList.Count > 0)
            {
                curPoint = pointList[pointList.Count - 1];
                m_CurBuyAveVal = Convert.ToInt32(curPoint.Y);
            }
            

            pointList = m_SellWaveManager.FilteredPointList;
            m_CurSellAveVal = -1;
            if (pointList.Count > 0)
            {
                curPoint = pointList[pointList.Count - 1];
                m_CurSellAveVal = Convert.ToInt32(curPoint.Y);
            }
        }

        // 매수, 매도 호가건수의 수렴발산을 나타낸다.
        private double m_InvDivBuySell = 0;
        public double InvDivBuySell
        {
            get { return m_InvDivBuySell; }
            set { m_InvDivBuySell = value; }
        }
        public void MakeBuyMidValueList(int a_CurIndex, string a_RegType, int a_MaxRange)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;
            PricePointList pointList = m_BuyWaveManager.PriceList;
            double midVal = Forecaster.GetForecastingVal(m_ForecastInfo, curTable, "매수총호가건수", a_RegType, a_CurIndex, a_MaxRange, false);
            if (curTable.GetRowCount() > 1)
            {
                EasyTrader.Wave.PricePoint newPoint = new EasyTrader.Wave.PricePoint();
                newPoint.X = a_CurIndex;
                newPoint.Y = midVal;
                pointList.Add(newPoint);
            }
        }

        public void MakeSellMidValueList(int a_CurIndex, string a_RegType, int a_MaxRange)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;
            PricePointList pointList = m_SellWaveManager.PriceList;
            // 먼저 목록을 비워준다.
            double midVal = Forecaster.GetForecastingVal(m_ForecastInfo, curTable, "매도총호가건수", a_RegType, a_CurIndex, a_MaxRange, false);
            if (curTable.GetRowCount() > 1)
            {
                EasyTrader.Wave.PricePoint newPoint = new EasyTrader.Wave.PricePoint();
                newPoint.X = a_CurIndex;
                newPoint.Y = midVal;
                pointList.Add(newPoint);
            }
        }

        public override int GetSignal(int a_DataCount)
        {
            int signalVal = GlobalVar.SignalNone;

            return signalVal;
        }

        // 이 함수는 호가 건수에 의해서 매도와 매수를 결정해 반환한다.
        // 퍼센트로 반환을 한다.
        public double GetBuySellSignal(int a_CurIndex)
        {
            double signalVal = GlobalVar.SignalNone;

            // 항상 매수 입장에서 모든 함수가 호출된다.
            double curSignal = m_InvDivBuySell = FindBuySellInvDivType(a_CurIndex, GlobalVar.RegressionType, GlobalVar.BuySellBeginRefRange);
            if (curSignal == 0)
                return signalVal;

            signalVal = ((9.0 - (Math.Abs(curSignal) - 1.0)) / 9.0) * 100.0;
            return curSignal > 0.0 ? signalVal : -signalVal;
        }

        public void MakeWave(int a_CurIndex)
        {
            if (m_BuyWaveManager != null)
            {
                m_BuyWaveManager.EasyTraderDataSet = m_EasyTraderDataSet;
                m_BuyWaveManager.MakeWaveListForBuy(a_CurIndex + 1);
            }
            if (m_SellWaveManager != null)
            {
                m_SellWaveManager.EasyTraderDataSet = m_EasyTraderDataSet;
                m_SellWaveManager.MakeWaveListForSell(a_CurIndex + 1);
            }
        }

        // 이 함수는 호가 잔량에 의해서 매도와 매수를 결정해 반환한다.
        // 퍼센트로 반환을 한다.
        public double GetBidsAsksSignal(int a_CurIndex)
        {
            double signalVal = GlobalVar.SignalNone;

            // 항상 매수 입장에서 모든 함수가 호출된다.
            double curSignal = FindBidsAsksInvDivType(a_CurIndex, GlobalVar.RegressionType, GlobalVar.ReferenceRange);
            if (curSignal == 0)
                return signalVal;

            signalVal = ((9.0 - (Math.Abs(curSignal) - 1.0)) / 9.0) * 100.0;
            return curSignal > 0.0 ? signalVal : -signalVal;
        }

        // 매수 총 호가 건수의 면적을 구한다.
        // 모든 호가건수를 다 더한 값이 된다.
        public int GetBuySquare(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;

            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            int totalSquare = 0;

            for (int i = 0; i < a_CurIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매수총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                totalSquare += buy;
            }

            return totalSquare;
        }

        public int GetFirstBuySell(int a_CurIndex, ref int a_BuyFirst, ref int a_SellFirst)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            a_BuyFirst = 0;
            a_SellFirst = 0;
            DataRow row = curTable.Rows[0];
            if (rowCount == 0)
                return 0;
            a_BuyFirst = Convert.ToInt32(row["매수총호가건수"]);
            a_SellFirst = Convert.ToInt32(row["매도총호가건수"]);

            return 1;
        }

        public int GetBuySellSquare(int a_CurIndex, ref int a_BuySquare, ref int a_SellSquare)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            int totalSquare = 0;
            a_BuySquare = 0;
            a_SellSquare = 0;
            DataRow row = curTable.Rows[0];
            if (rowCount == 0)
                return 0;
            int firstBuy = Convert.ToInt32(row["매수총호가건수"]);
            int firstSell = Convert.ToInt32(row["매도총호가건수"]);
            // 매도와 매수의 큰값으로 정한다.
            int openVal = Math.Max(firstBuy, firstSell);

            row = curTable.Rows[a_CurIndex];
            if (row["매도총호가건수"] == DBNull.Value)
                return 0;
            int buy = Convert.ToInt32(row["매수총호가건수"]);
            int sell = Convert.ToInt32(row["매도총호가건수"]);
            int firstTrend = GlobalVar.PriceFlat;
            int deltaBuySell = buy - sell;
            if (deltaBuySell >= 0)
                firstTrend = GlobalVar.PriceUp;
            else
                firstTrend = GlobalVar.PriceDown;

            for (int i = a_CurIndex; i >= 0; i--)
            {
                row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                buy = Convert.ToInt32(row["매수총호가건수"]) - openVal;
                sell = Convert.ToInt32(row["매도총호가건수"]) - openVal;
                if (buy > 0)
                    a_BuySquare += buy;
                if (sell > 0)
                    a_SellSquare += sell;

                int curTrend = GlobalVar.PriceFlat;
                firstBuy = Convert.ToInt32(row["매수총호가건수"]);
                firstSell = Convert.ToInt32(row["매도총호가건수"]);
                deltaBuySell = firstBuy - firstSell;
                if (deltaBuySell >= 0)
                    curTrend = GlobalVar.PriceUp;
                else
                    curTrend = GlobalVar.PriceDown;
                if (firstTrend != curTrend)
                {
                    int k = 0;
                    k = k + 1;
                    break;
                }
            }

            return totalSquare = Math.Max(a_BuySquare, a_SellSquare);
        }


        public int GetHogaFromStart(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;

            DataRow row = curTable.Rows[0];
            if (rowCount == 0)
                return 0;
            int firstBuy = Convert.ToInt32(row["매수총호가건수"]);
            int firstSell = Convert.ToInt32(row["매도총호가건수"]);
            // 매도와 매수의 큰값으로 정한다.
            int openVal = Math.Max(firstBuy, firstSell);

            row = curTable.Rows[a_CurIndex];
            if (row["매도총호가건수"] == DBNull.Value)
                return 0;
            int buy = Convert.ToInt32(row["매수총호가건수"]);
            int sell = Convert.ToInt32(row["매도총호가건수"]);
            int maxBuy = -99999999;
            int maxSell = -99999999;
            for (int i = a_CurIndex; i >= 0; i--)
            {
                row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                buy = Convert.ToInt32(row["매수총호가건수"]);
                sell = Convert.ToInt32(row["매도총호가건수"]);
                if (buy > maxBuy)
                    maxBuy = buy;
                if (sell > maxSell)
                    maxSell = sell;
            }

            int maxHoga = Math.Max(maxBuy, maxSell);

            return maxHoga - openVal;
        }


        public double GetAveBuySellMaxMinDelta(int a_CurIndex)
        {
            double buy = GetBuyAveVal(a_CurIndex);
            double sell = GetSellAveVal(a_CurIndex);
            if (buy == -1.0 || sell == -1.0)
                return -1.0;
            double maxBuy = buy;
            double minBuy = buy;
            double maxSell = sell;
            double minSell = sell;
            double deltaBuySell = buy - sell;
            int firstTrend = GlobalVar.PriceFlat;
            if (deltaBuySell > 0)
                firstTrend = GlobalVar.PriceUp;
            else if (deltaBuySell < 0)
                firstTrend = GlobalVar.PriceDown;
            if (firstTrend == GlobalVar.PriceFlat)
                return -1.0;
            for (int i = a_CurIndex; i > -1; i--)
            {
                buy = GetBuyAveVal(i);
                sell = GetSellAveVal(i);
                if (buy > maxBuy)
                    maxBuy = buy;
                if (buy < minBuy)
                    minBuy = buy;
                if (sell > maxSell)
                    maxSell = sell;
                if (sell < minSell)
                    minSell = sell;
                deltaBuySell = buy - sell;
                int curTrend = GlobalVar.PriceFlat;
                if (deltaBuySell > 0)
                    curTrend = GlobalVar.PriceUp;
                else if (deltaBuySell < 0)
                    curTrend = GlobalVar.PriceDown;
                if (firstTrend != curTrend)
                    break;
            }

            if (firstTrend == GlobalVar.PriceUp)
            {
                deltaBuySell = maxBuy - minSell;
            }
            else if (firstTrend == GlobalVar.PriceDown)
            {
                deltaBuySell = maxSell - minBuy;
            }

            return deltaBuySell;
        }

        // 전체 공간 점유율을 계산한다.
        public int GetTotalBuySellSquareOld(int a_CurIndex, ref int a_BuySquare, ref int a_SellSquare, ref int a_TotalSquare)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            int totalSquare = 0;
            a_BuySquare = 0;
            a_SellSquare = 0;
            a_TotalSquare = 0;
            DataRow row = curTable.Rows[0];
            if (rowCount == 0)
                return 0;
            int firstBuy = Convert.ToInt32(row["매수총호가건수"]);
            int firstSell = Convert.ToInt32(row["매도총호가건수"]);
            if (rowCount == 1)
            {
                a_BuySquare = firstBuy;
                a_SellSquare = firstSell;
                a_TotalSquare = Math.Max(a_BuySquare, a_SellSquare);
                return a_TotalSquare;
            }
            // 매도와 매수의 큰값으로 정한다.
            int openVal = Math.Max(firstBuy, firstSell);

            row = curTable.Rows[a_CurIndex];
            if (row["매도총호가건수"] == DBNull.Value)
                return 0;
           for (int i = a_CurIndex; i >= 0; i--)
            {
                row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매수총호가건수"]) - openVal;
                int sell = Convert.ToInt32(row["매도총호가건수"]) - openVal;
                if (buy > 0)
                    a_BuySquare += buy;
                if (sell > 0)
                    a_SellSquare += sell;
                a_TotalSquare += Math.Max(buy, sell);
            }

            return totalSquare = a_TotalSquare;
        }

        public int GetTotalBuySellSquare(int a_CurIndex, ref int a_BuySquare, ref int a_SellSquare, ref int a_TotalSquare)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            int totalSquare = 0;
            a_BuySquare = 0;
            a_SellSquare = 0;
            a_TotalSquare = 0;
            DataRow row = curTable.Rows[0];
            if (rowCount == 0)
                return 0;
            int firstBuy = Convert.ToInt32(row["매수총호가건수"]);
            int firstSell = Convert.ToInt32(row["매도총호가건수"]);
            if (rowCount == 1)
            {
                a_BuySquare = firstBuy;
                a_SellSquare = firstSell;
                a_TotalSquare = Math.Max(a_BuySquare, a_SellSquare);
                return a_TotalSquare;
            }
            // 매도와 매수의 큰값으로 정한다.
            int openVal = Math.Max(firstBuy, firstSell);

            row = curTable.Rows[a_CurIndex];
            if (row["매도총호가건수"] == DBNull.Value)
                return 0;
            for (int i = a_CurIndex; i >= 0; i--)
            {
                row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                a_BuySquare += buy;
                a_SellSquare += sell;
                    
                a_TotalSquare += Math.Max(buy, sell);
            }

            return totalSquare = a_TotalSquare;
        }

        // 매도 총 호가 건수의 면적을 구한다.
        // 모든 호가건수를 다 더한 값이 된다.
        public int GetSellSquare(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;

            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            int totalSquare = 0;
            if (rowCount == 0)
                return 0;

            for (int i = 0; i < a_CurIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매도총호가건수"]);
                totalSquare += buy;
            }

            return totalSquare;
        }

        // 이 함수는 매수와 매도의 시간 점유율을 계산한다.
        public int GetBuySellTimeOccupation(int a_CurIndex, ref int a_OccBuy, ref int a_OccSell)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (a_CurIndex < 0)
                a_CurIndex = 0;
            if (a_CurIndex > rowCount - 1)
                a_CurIndex = rowCount - 1;
            int totalSquare = 0;
            if (rowCount == 0)
                return 0;
            a_OccBuy = 0;
            a_OccSell = 0;
            for (int i = 0; i < a_CurIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                if (buy > sell)
                    a_OccBuy++;
                else if (sell > buy)
                    a_OccSell++;
            }

            return totalSquare;
        }

        public int GetHigherBuySell(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            // 호가 잔량은 8:00 부터 수집되므로 다른 데이터 보다 60개가 더 많다.
            // 따라서 60을 더해주고 인덱스를 얻기 위해서 - 1을 해준다.
            int curIndex = rowCount - 1;
            DataRow row = curTable.Rows[curIndex];
            if (row["매수총호가건수"] == DBNull.Value || row["매도총호가건수"] == DBNull.Value)
                return 0;
            int bids = Convert.ToInt32(row["매수총호가건수"]);
            int asks = Convert.ToInt32(row["매도총호가건수"]);
            // 큰 것에서 작은 것을 빼어 그 차이를 반환한다.
            return Math.Max(bids, asks);
        }

        public EasyTrader.Signal.HighLowInfo FindBuySignalHighLow(int a_CurIndex, EasyTrader.Wave.PriceWave a_LastSignalWave)
        {
            if (a_CurIndex < 0 || a_LastSignalWave == null)
                return m_BuyHighLowInfo;

            if (m_EasyTraderDataSet == null)
                return m_BuyHighLowInfo;
           FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return m_BuyHighLowInfo;
            int rowCount = curTable.GetRowCount();
            if (rowCount == 0)
                return m_BuyHighLowInfo;

            int startX = rowCount - 1;
            startX = Math.Min(a_CurIndex, startX);
            
            DataRow row = curTable.Rows[startX];
            m_BuyHighLowInfo.BuyHigh = -1000000; 
            m_BuyHighLowInfo.BuyLow = 10000000; 

            int endX = a_LastSignalWave.StartX;
            endX = Math.Max(a_LastSignalWave.StartX - 10, 0);
            for (int j = startX; j >= endX; j--)
            {
                row = curTable.Rows[j];
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                
                if (buy != 0 && buy < m_BuyHighLowInfo.BuyLow)
                {
                    m_BuyHighLowInfo.BuyLow = buy;
                }
                if (buy != 0 && buy > m_BuyHighLowInfo.BuyHigh)
                {
                    m_BuyHighLowInfo.BuyHigh = buy;
                }
            }
            return m_BuyHighLowInfo;
        }

        public EasyTrader.Signal.HighLowInfo FindSellSignalHighLow(int a_CurIndex, EasyTrader.Wave.PriceWave a_LastSignalWave)
        {
            if (a_CurIndex < 0 || a_LastSignalWave == null)
                return m_SellHighLowInfo;

            if (m_EasyTraderDataSet == null)
                return m_SellHighLowInfo;
            FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return m_SellHighLowInfo;
            int rowCount = curTable.GetRowCount();
            if (rowCount == 0)
                return m_SellHighLowInfo;

            int startX = rowCount - 1;
            startX = Math.Min(a_CurIndex, startX);

            DataRow row = curTable.Rows[startX];
            m_SellHighLowInfo.SellHigh = -1000000;
            m_SellHighLowInfo.SellLow = 10000000;

            int endX = a_LastSignalWave.StartX;
            endX = Math.Max(a_LastSignalWave.StartX - 10, 0);
            for (int j = startX; j >= endX; j--)
            {
                row = curTable.Rows[j];
                int sell = Convert.ToInt32(row["매도총호가건수"]);

                if (sell != 0 && sell < m_SellHighLowInfo.SellLow)
                {
                    m_SellHighLowInfo.SellLow = sell;
                }
                if (sell != 0 && sell > m_SellHighLowInfo.SellHigh)
                {
                    m_SellHighLowInfo.SellHigh = sell;
                }
            }
            return m_SellHighLowInfo;
        }

        public int GetBuyDayHigh(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            int curIndex = Math.Min(a_CurIndex, rowCount - 1);
            int maxBuy = -99999;
            for (int i = 0; i <= curIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매수총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                if (buy > maxBuy)
                {
                    maxBuy = buy;
                }
            }

            return maxBuy;
        }

        public int GetBuyDayHigh(int a_CurIndex, ref int a_SellVal)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            int curIndex = Math.Min(a_CurIndex, rowCount - 1);
            int maxBuy = -99999;
            a_SellVal = 0;
            for (int i = 0; i <= curIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매수총호가건수"] == DBNull.Value)
                    return 0;
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                if (buy > maxBuy)
                {
                    maxBuy = buy;
                    a_SellVal = sell;
                }
            }

            return maxBuy;
        }

        public int GetSellDayHigh(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            int curIndex = Math.Min(a_CurIndex, rowCount - 1);
            int maxSell = -99999;
            for (int i = 0; i <= curIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                if (sell > maxSell)
                {
                    maxSell = sell;
                }
            }

            return maxSell;
        }

        public int GetSellDayHigh(int a_CurIndex, ref int a_BuyVal)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            int curIndex = Math.Min(a_CurIndex, rowCount - 1);
            int maxSell = -99999;
            a_BuyVal = 0;
            for (int i = 0; i <= curIndex; i++)
            {
                DataRow row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return 0;
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                if (sell > maxSell)
                {
                    maxSell = sell;
                    a_BuyVal = buy;
                }
            }

            return maxSell;
        }

        public int GetSellHighByPeak(int a_CurIndex, ref int a_OldDaySellHigh, ref int a_CurSellHigh)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return -1;
            int curIndex = Math.Min(a_CurIndex, rowCount - 1);
            DataRow row = curTable.Rows[curIndex];
            if (row["매도총호가건수"] == DBNull.Value)
                return 0;
            a_CurSellHigh = Convert.ToInt32(row["매도총호가건수"]);
            a_OldDaySellHigh = a_CurSellHigh;
            int maxBuy = Convert.ToInt32(row["매수총호가건수"]);
            for (int i = 0; i <= curIndex; i++)
            {
                row = curTable.Rows[i];
                if (row["매도총호가건수"] == DBNull.Value)
                    return -1;
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                // 현재 범위에서 제일 큰값
                if (sell > a_CurSellHigh)
                {
                    a_CurSellHigh = sell;
                    maxBuy = buy;
                }
                
                // 현재 범위에서 제일 큰값이 이전 범위의 일고가보다 크면,
                // 현재 범위에서 제일 큰값이 상대값보다 크면
                int aveSell = Convert.ToInt32(GetSellAveVal(i));
                if (a_CurSellHigh > a_OldDaySellHigh && a_CurSellHigh > maxBuy)
                {
                    int delataSell = a_CurSellHigh - aveSell;
                    // 현재 값이 최고가에서 일정 범위를 내려오면
                    if (aveSell != -1 && delataSell > GlobalVar.MinHogaLimit)
                    {
                        a_OldDaySellHigh = a_CurSellHigh;
                    }
                }
            }

            return 1;
        }

        public int GetBuyHighByPeak(int a_CurIndex, ref int a_OldDayBuyHigh, ref int a_CurBuyHigh)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return -1;
            int curIndex = Math.Min(a_CurIndex, rowCount - 1);
            DataRow row = curTable.Rows[curIndex];
            if (row["매도총호가건수"] == DBNull.Value)
                return 0;
            a_CurBuyHigh = Convert.ToInt32(row["매수총호가건수"]);
            a_OldDayBuyHigh = a_CurBuyHigh;
            int maxSell = Convert.ToInt32(row["매도총호가건수"]);
            for (int i = 0; i <= curIndex; i++)
            {
                row = curTable.Rows[i];
                if (row["매수총호가건수"] == DBNull.Value)
                    return -1;
                int sell = Convert.ToInt32(row["매도총호가건수"]);
                int buy = Convert.ToInt32(row["매수총호가건수"]);
                // 현재 범위에서 제일 큰값
                if (buy > a_CurBuyHigh)
                {
                    a_CurBuyHigh = buy;
                    maxSell = sell;
                }

                // 현재 범위에서 제일 큰값이 이전 범위의 일고가보다 크면,
                // 현재 범위에서 제일 큰값이 상대값보다 크면
                int aveBuy = Convert.ToInt32(GetBuyAveVal(i));
                if (a_CurBuyHigh > a_OldDayBuyHigh && a_CurBuyHigh > maxSell)
                {
                    int delataBuy = a_CurBuyHigh - aveBuy;
                    // 현재 값이 최고가에서 일정 범위를 내려오면
                    if (aveBuy != -1 && delataBuy > GlobalVar.MinHogaLimit)
                    {
                        a_OldDayBuyHigh = a_CurBuyHigh;
                        a_CurBuyHigh = buy;
                    }
                }
            }

            return 1;
        }

        // 이 함수는 파동의 고점저점을 구한다. 이때 고가와 저가, 종가에 대하여 각각 구한다.
        public void FindBuyWaveHighLow(EasyTrader.Wave.PriceWave a_Wave)
        {
            if (a_Wave == null || m_EasyTraderDataSet == null)
                return;

            FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;

            int startX = a_Wave.StartX - GlobalVar.ForecastCompLen;
            startX = Math.Max(0, startX);
            int endX = Math.Min(a_Wave.EndX, curTable.GetRowCount() - 1);
            DataRow row = curTable.Rows[startX];
            int high = -1000000;
            int low = 1000000;
            for (int j = startX; j <= endX; j++)
            {
                row = curTable.Rows[j];
                int val = Convert.ToInt32(row["매수총호가건수"]);
                if (val != 0 && val > high)
                {
                    high = val;
                    a_Wave.HighX = j;
                    a_Wave.HighY = high;
                }
                if (val != 0 && val < low)
                {
                    low = val;
                    a_Wave.LowX = j;
                    a_Wave.LowY = low;
                }
            }
        }

        // 이 함수는 파동구간에 있는 평균값의 고점저점을 구한다.
        public void FindBuyWaveAveHighLow(EasyTrader.Wave.PriceWave a_Wave, ref double a_Max, ref double a_Min)
        {
            if (a_Wave == null || m_EasyTraderDataSet == null)
                return;

            FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;

            int startX = a_Wave.StartX;
            startX = Math.Max(3, startX);
            if (startX > curTable.GetRowCount() - 1)
                return;

            int endX = Math.Min(a_Wave.EndX, curTable.GetRowCount() - 1);
            a_Min = GetBuyAveVal(startX);
            a_Max = a_Min;
            for (int j = startX; j <= endX; j++)
            {
                double buy = GetBuyAveVal(j);
                if (buy > a_Max)
                    a_Max = buy;
                if (buy < a_Min)
                    a_Min = buy;
            }
        }

        // 이 함수는 파동구간에 있는 평균값의 고점저점을 구한다.
        public void FindSellWaveAveHighLow(EasyTrader.Wave.PriceWave a_Wave, ref double a_Max, ref double a_Min)
        {
            if (a_Wave == null || m_EasyTraderDataSet == null)
                return;

            FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;

            int startX = a_Wave.StartX;
            startX = Math.Max(3, startX);
            if (startX > curTable.GetRowCount() - 1)
                return;

            int endX = Math.Min(a_Wave.EndX, curTable.GetRowCount() - 1);
            a_Min = GetSellAveVal(startX);
            a_Max = a_Min;
            for (int j = startX; j <= endX; j++)
            {
                double sell = GetSellAveVal(j);
                if (sell > a_Max)
                    a_Max = sell;
                if (sell < a_Min)
                    a_Min = sell;
            }
        }

        // 이 함수는 파동의 고점저점을 구한다. 이때 고가와 저가, 종가에 대하여 각각 구한다.
        public void FindSellWaveHighLow(EasyTrader.Wave.PriceWave a_Wave)
        {
            if (a_Wave == null || m_EasyTraderDataSet == null)
                return;

            FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return;

            int startX = a_Wave.StartX - GlobalVar.ForecastCompLen;
            startX = Math.Max(0, startX);
            int endX = Math.Min(a_Wave.EndX, curTable.GetRowCount() - 1);
            DataRow row = curTable.Rows[startX];
            int high = -1000000;
            int low = 1000000;
            for (int j = startX; j <= endX; j++)
            {
                row = curTable.Rows[j];
                int val = Convert.ToInt32(row["매도총호가건수"]);
                if (val != 0 && val > high)
                {
                    high = val;
                    a_Wave.HighX = j;
                    a_Wave.HighY = high;
                }
                if (val != 0 && val < low)
                {
                    low = val;
                    a_Wave.LowX = j;
                    a_Wave.LowY = low;
                }
            }
        }

        public int GetHigherBidAsk(int a_CurIndex)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            // 호가 잔량은 8:00 부터 수집되므로 다른 데이터 보다 60개가 더 많다.
            // 따라서 60을 더해주고 인덱스를 얻기 위해서 - 1을 해준다.
            int curIndex = rowCount - 1;
            DataRow row = curTable.Rows[curIndex];
            if (row["매수총호가수량"] == DBNull.Value || row["매도총호가수량"] == DBNull.Value)
                return 0;
            int bids = Convert.ToInt32(row["매수총호가수량"]);
            int asks = Convert.ToInt32(row["매도총호가수량"]);
            // 큰 것에서 작은 것을 빼어 그 차이를 반환한다.
            return Math.Max(bids, asks);
        }
        // 호가 잔량에 대한 차이를 반환한다.
        // 항상 큰 값에서 작은 값을 빼서 반환한다.
        public int GetBidAskDelta(int a_DataCount)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            // 호가 잔량은 8:00 부터 수집되므로 다른 데이터 보다 60개가 더 많다.
            // 따라서 60을 더해주고 인덱스를 얻기 위해서 - 1을 해준다.
            int rowCount = curTable.GetRowCount();
            if (rowCount == 0)
                return 0;

            int curIndex = Math.Min(rowCount - 1, a_DataCount + 60 - 1);
            DataRow row = curTable.Rows[curIndex];

            if (row["매수총호가수량"] == DBNull.Value || row["매도총호가수량"] == DBNull.Value)
                return 0;
            int bids = Convert.ToInt32(row["매수총호가수량"]);
            int asks = Convert.ToInt32(row["매도총호가수량"]);
            // 큰 것에서 작은 것을 빼어 그 차이를 반환한다.
            return (Math.Max(bids, asks) - Math.Min(bids, asks));
        }

        // 가장 최근의 호가 잔량에 대한 차이를 반환한다.
        // 항상 큰 값에서 작은 값을 빼서 반환한다.
        public int GetLastBidAskDelta()
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            // 호가 잔량은 8:00 부터 수집되므로 다른 데이터 보다 60개가 더 많다.
            // 따라서 60을 더해주고 인덱스를 얻기 위해서 - 1을 해준다.
            int curIndex = rowCount - 1;
            DataRow row = curTable.Rows[curIndex];
            if (row["매수총호가수량"] == DBNull.Value || row["매도총호가수량"] == DBNull.Value)
                return 0;
            int bids = Convert.ToInt32(row["매수총호가수량"]);
            int asks = Convert.ToInt32(row["매도총호가수량"]);
            // 큰 것에서 작은 것을 빼어 그 차이를 반환한다.
            return (Math.Max(bids, asks) - Math.Min(bids, asks));
        }

        // 호가 건수에 대한 차이를 반환한다.
        // 항상 큰 값에서 작은 값을 빼서 반환한다.
        public int GetBuySellDelta(int a_DataCount)
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            // 호가 잔량은 8:00 부터 수집되므로 다른 데이터 보다 60개가 더 많다.
            // 따라서 60을 더해주고 인덱스를 얻기 위해서 - 1을 해준다.
            int rowCount = curTable.GetRowCount();
            if (rowCount == 0)
                return 0;

            int curIndex = Math.Min(rowCount - 1, a_DataCount + 60 - 1);
            DataRow row = curTable.Rows[curIndex];
            if (row["매수총호가건수"] == DBNull.Value || row["매도총호가건수"] == DBNull.Value)
                return 0;
            int bids = Convert.ToInt32(row["매수총호가건수"]);
            int asks = Convert.ToInt32(row["매도총호가건수"]);
            // 큰 것에서 작은 것을 빼어 그 차이를 반환한다.
            return (Math.Max(bids, asks) - Math.Min(bids, asks));
        }

        // 가장 최근의 호가 건수에 대한 차이를 반환한다.
        // 항상 큰 값에서 작은 값을 빼서 반환한다.
        public int GetLastBuySellDelta()
        {
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return 0;
            int rowCount = curTable.Rows.Count;
            if (rowCount == 0)
                return 0;
            // 호가 잔량은 8:00 부터 수집되므로 다른 데이터 보다 60개가 더 많다.
            // 따라서 60을 더해주고 인덱스를 얻기 위해서 - 1을 해준다.
            int curIndex = rowCount - 1;
            DataRow row = curTable.Rows[curIndex];
            if (row["매수총호가건수"] == DBNull.Value || row["매도총호가건수"] == DBNull.Value)
                return 0;
            int bids = Convert.ToInt32(row["매수총호가건수"]);
            int asks = Convert.ToInt32(row["매도총호가건수"]);
            // 큰 것에서 작은 것을 빼어 그 차이를 반환한다.
            return (Math.Max(bids, asks) - Math.Min(bids, asks));
        }

        public ForecastingInfo GetForecastingInfo(string a_ColName, string a_RegType, int a_MaxRange)
        {
            if (a_ColName == "")
                return null;
            EasyTrader.DataSet.ETDataTable curTable = (EasyTrader.DataSet.ETDataTable)m_EasyTraderDataSet.GetFutureMstTable();
            return Forecaster.GetForecastingInfo(curTable, a_ColName, a_RegType, a_MaxRange);
        }

        public ForecastingInfo GetForecastingInfoWithOpen(string a_ColName, string a_RegType, int a_MaxRange)
        {
            if (a_ColName == "")
                return null;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return null;
            double openVal = curTable.GetOpenVal(a_ColName);
            return Forecaster.GetForecastingInfoWithOpen(curTable, a_ColName, a_RegType, a_MaxRange, openVal);
        }

        public ForecastingInfo GetForecastingInfoWithOpen(string a_ColName, string a_RegType, int a_EndX, int a_MaxRange)
        {
            if (a_ColName == "")
                return null;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return null;
            double openVal = curTable.GetOpenVal(a_ColName);
            return Forecaster.GetForecastingInfoWithOpen(curTable, a_ColName, a_RegType, a_EndX, a_MaxRange, openVal);
        }

        public ForecastingInfo GetForecastingInfo(string a_ColName, string a_RegType, int a_DayIndex, int a_MaxRange, bool a_AllowZero)
        {
            if (a_ColName == "")
                return null;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            int refRange = a_DayIndex > a_MaxRange ? a_MaxRange : a_DayIndex + 1;
            return Forecaster.GetForecastingInfo(curTable, a_ColName, a_RegType, a_DayIndex, refRange, a_AllowZero);
        }

        public int GetForecastingInfo(ForecastingInfo a_Fore, string a_ColName, string a_RegType, int a_DayIndex, int a_MaxRange, bool a_AllowZero)
        {
            if (a_ColName == "" || a_Fore == null)
                return -1;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            if (curTable.GetRowCount() == 0)
                return -1;
            return Forecaster.GetForecastingInfo(a_Fore, curTable, a_ColName, a_RegType, a_DayIndex, a_MaxRange, a_AllowZero);
        }

        public int GetForecastingInfo(ForecastingInfo a_Fore, string a_ColName, string a_RegType, int a_DayIndex, bool a_AllowZero)
        {
            if (a_ColName == "" || a_Fore == null)
                return -1;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            if (curTable.GetRowCount() == 0)
                return -1;
            return Forecaster.GetForecastingInfoBeginEnd(a_Fore, curTable, a_ColName, a_RegType, 0, a_DayIndex, a_AllowZero);
        }

        public int FindBuySellInvDivType(string a_RegType, int a_MaxRange)
        {
            int invdiv = 0;
            ForecastingInfo buyForecast = GetForecastingInfo("매수총호가건수", a_RegType, a_MaxRange);
            ForecastingInfo sellForecast = GetForecastingInfo("매도총호가건수", a_RegType, a_MaxRange);
            if (buyForecast == null || sellForecast == null)
                return invdiv;
            return SignalManager.FindInvDivType(buyForecast, sellForecast);
        }

        public int FindBidsAsksInvDivType(string a_RegType, int a_MaxRange)
        {
            int invdiv = 0;
            ForecastingInfo buyForecast = GetForecastingInfo("매수총호가수량", a_RegType, a_MaxRange);
            ForecastingInfo sellForecast = GetForecastingInfo("매도총호가수량", a_RegType, a_MaxRange);
            if (buyForecast == null || sellForecast == null)
                return invdiv;
            return SignalManager.FindInvDivType(buyForecast, sellForecast);
        }

        public int FindBuySellInvDivType(int a_CurIndex, string a_RegType, int a_MaxRange)
        {
            int invdiv = 0;
            int buy = GetForecastingInfo(buyInfo, "매수총호가건수", a_RegType, a_CurIndex, a_MaxRange, false);
            int sell = GetForecastingInfo(sellInfo, "매도총호가건수", a_RegType, a_CurIndex, a_MaxRange, false);
            if (buy < 0 || sell < 0)
                return invdiv;
            return SignalManager.FindInvDivType(buyInfo, sellInfo);
        }

        public int FindBidsAsksInvDivType(int a_CurIndex, string a_RegType, int a_MaxRange)
        {
            int invdiv = 0;
            int bids = GetForecastingInfo(bidsInfo, "매수총호가수량", a_RegType, a_CurIndex, a_MaxRange, false);
            int asks = GetForecastingInfo(asksInfo, "매도총호가수량", a_RegType, a_CurIndex, a_MaxRange, false);
            if (bids < 0 || asks < 0)
                return invdiv;
            return SignalManager.FindInvDivType(bidsInfo, asksInfo);
        }
        private ForecastingInfo m_FullBids = new ForecastingInfo();
        private ForecastingInfo m_FullAsks = new ForecastingInfo();
        private ForecastingInfo m_FullBuy = new ForecastingInfo();
        private ForecastingInfo m_FullSell = new ForecastingInfo();
        public int FindBidsAsksInvDivType(int a_CurIndex, string a_RegType)
        {
            int invdiv = 0;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return invdiv;
            if (curTable.GetRowCount() == 0)
                return invdiv;

            int bids = m_Forecaster.GetForecastingInfoBeginEnd(m_FullBids, curTable, "매수총호가수량", a_RegType, 0, a_CurIndex, false);
            int asks = m_Forecaster.GetForecastingInfoBeginEnd(m_FullAsks, curTable, "매도총호가수량", a_RegType, 0, a_CurIndex, false);
            if (bids < 0 || asks < 0)
                return invdiv;
            return SignalManager.FindInvDivType(bidsInfo, asksInfo);
        }

        public int FindBuySellInvDivType(int a_CurIndex, string a_RegType)
        {
            int invdiv = 0;
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return invdiv;
            if (curTable.GetRowCount() == 0)
                return invdiv;

            int bids = m_Forecaster.GetForecastingInfoBeginEnd(m_FullBuy, curTable, "매수총호가건수", a_RegType, 0, a_CurIndex, false);
            int asks = m_Forecaster.GetForecastingInfoBeginEnd(m_FullSell, curTable, "매도총호가건수", a_RegType, 0, a_CurIndex, false);
            if (bids < 0 || asks < 0)
                return invdiv;
            return SignalManager.FindInvDivType(bidsInfo, asksInfo);
        }

        // 현재까지 호가 잔량이 만났는지 조사한다.
        // 만나지 않았으면 0, 만났으면 그 회수를 반환한다.
        // 오류가 발생했을 경우는 -1을 반환한다.
        public int GetBidsAsksCrossCount(int a_CurIndex, ref int a_MaxLen)
        {
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            return m_Forecaster.GetCrossedCount(a_CurIndex, curTable, "매수총호가수량", "매도총호가수량", ref a_MaxLen);
        }

        // 현재까지 호가 건수가 만났는지 조사한다.
        // 만나지 않았으면 0, 만났으면 그 회수를 반환한다.
        // 오류가 발생했을 경우는 -1을 반환한다.
        public int GetBuySellCrossCount(int a_CurIndex, ref int a_MaxLen)
        {
            EasyTrader.FutureMstTable curTable = m_EasyTraderDataSet.GetFutureMstTable();
            if (curTable == null)
                return -1;
            return m_Forecaster.GetCrossedCount(a_CurIndex, curTable, "매수총호가건수", "매도총호가건수", ref a_MaxLen);
        }
    }
}
